package com.hzbank.aaronkotlin

import android.graphics.Bitmap
import android.text.TextUtils
import android.view.LayoutInflater
import android.view.View.GONE
import android.view.View.VISIBLE
import android.view.ViewGroup
import com.aaron.functionLibs.recycler.BaseAdapter
import com.aaron.functionLibs.recycler.BaseViewHolder
import com.aaron.smartktv.core.tool.XGravity
import com.aaron.smartktv.core.tool.XPenType
import com.hzbank.aaronkotlin.DocumentPrewActivity.Companion.broadRecordMap
import com.hzbank.aaronkotlin.databinding.ItemDocumentPrewBinding

class DocumentPrewAdapter(val layoutInflater: LayoutInflater, datas: MutableList<Bitmap>)
    : BaseAdapter<ItemDocumentPrewBinding>(datas) {

    override fun getViewBinding(parent: ViewGroup, viewType: Int): ItemDocumentPrewBinding =
        ItemDocumentPrewBinding.inflate(layoutInflater, parent, false)

    override fun operationLayoutSize(viewBinding: ItemDocumentPrewBinding) {
        val width = viewBinding.root.context.getScreenSize().x
        val height = viewBinding.root.context.getScreenSize().y

        ("item 宽=$width--高=$height").showLog()

        viewBinding.root.layoutParams = ViewGroup.LayoutParams(width,
            height)
        viewBinding.bzInputL.visibility = GONE

    }

    override fun operationHolder(holder: BaseViewHolder<ItemDocumentPrewBinding>, position: Int) {

        if(null == datas || datas.isEmpty()) return

        val bmp: Bitmap = datas.get(position) as Bitmap

        if(null == bmp
            || bmp!!.isRecycled) return

        binding.documentPage.loadBitmap(bmp!!, XGravity.GravityCenter)
        binding.documentPage.setPenType(XPenType.NULL)

        if(null == broadRecordMap) broadRecordMap = mutableMapOf()

        if(broadRecordMap.containsKey(position)){
            ("列表监听--已经存在画板不复用").showLog()

        }else{
            broadRecordMap.put(position, binding.documentPage)
            ("列表监听--position1=$position").showLog()
        }

    }
}